<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 2020/6/13
  Time: 14:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title>登录</title>
    <script src="<%=basePath%>static/js/jquery-1.11.3.min.js"></script>
    <link rel="stylesheet" href="<%=basePath%>static/css/pintuer.css">
    <link rel="stylesheet" href="<%=basePath%>static/css/admin.css">
    <script src="<%=basePath%>static/js/pintuer.js"></script>
    <script src="<%=basePath%>static/js/bootstrap.min.js"></script>
<%--    <script type="text/javascript">--%>
<%--        //切换验证码--%>
<%--        function refreshCode(){--%>
<%--            //1.获取验证码图片对象--%>
<%--            var vcode = document.getElementById("vcode");--%>
<%--            //2.设置其src属性，加时间戳--%>
<%--            vcode.src = "${pageContext.request.contextPath}/CheckCodeServlet01?time="+new Date().getTime();--%>
<%--        }--%>
<%--    </script>--%>
</head>
<body>
<div class="bg"></div>
<div class="container">
    <div class="line bouncein">
        <div class="xs6 xm4 xs3-move xm4-move">
            <div style="height:20px;"></div>
            <div class="media media-y margin-big-bottom">
            </div>
            <form action="<%=basePath%>login" method="post">
                <div class="panel loginbox">
                    <div class="text-center margin-big padding-big-top"><h1>教务管理中心</h1></div>
                    <div class="panel-body" style="padding:30px; padding-bottom:10px; padding-top:10px;">
                        <p id="errorMessage"></p>
                        <div class="form-group">
                            <div class="field field-icon-right">
                                <input id="userName" type="text" class="input input-big" name="userName" placeholder="登录账号" data-validate="required:请填写账号" />
                                <span class="icon icon-user margin-small"></span>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="field field-icon-right">
                                <input id="pwd" type="password" class="input input-big" name="password" placeholder="登录密码" data-validate="required:请填写密码" />
                                <span class="icon icon-key margin-small"></span>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="field field-icon-right">
                                <select id="select_role">
                                    <option value="admin">admin</option>
                                    <option value="manager">manager</option>
                                    <option value="student">student</option>
                                    <option value="teacher">teacher</option>
                                </select>
                            </div>
                        </div>
<%--                        <div class="form-group">--%>
<%--                            <div class="field">--%>
<%--                                <input type="text" class="form-control" id="verifycode" name="verifycode" placeholder="填写右侧的验证码" data-validate="required:请填写右侧的验证码" />--%>
<%--                                <a href="javascript:refreshCode();">--%>
<%--                                    <img src="${pageContext.request.contextPath}/CheckCodeServlet01" title="看不清点击刷新" id="vcode"/>--%>
<%--                                </a>--%>
<%--&lt;%&ndash;                                <img src="images/passcode.jpg" alt="" width="100" height="32" class="passcode" style="height:43px;cursor:pointer;" onclick="this.src=this.src+'?'">&ndash;%&gt;--%>

<%--                            </div>--%>
<%--                        </div>--%>
                    </div>
                    <div style="padding:30px;">
                        <input type="button" class="button button-block bg-main text-big input-big" value="登录" onclick="login()">
                    </div>
                </div>
            </form>
            <!-- 出错显示的信息框 -->
            <div class="alert alert-warning alert-dismissible" role="alert" hidden>
                <button type="button" class="close" data-dismiss="alert" >
                    <span>&times;</span>
                </button>
                <strong>${login_msg}</strong>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    function login() {
        var userName = $("[name='userName']").val();//获取输入的账号
        var userPwd = $("[name='password']").val();//获取输入的密码
        //$("#sel option:selected").val()
        var userRole = $("#select_role option:selected").val();
        /*console.log(userRole);*/
        $.ajax({
            url: "<%=basePath%>sys/login",
            type: "post",
            data: {"userName": userName, "password": userPwd, "userRole": userRole},
            success: function (data) {
                console.log(data);
                if (data.status == 200) {
                    location.href = "<%=basePath%>sys/index";
                } else {
                    $("#errorMessage").text(data.message);
                }
            },
            error: function (data) {
                $("#errorMessage").text(data.responseText);
            }
        });
    }
</script>
</html>
